const db = require('../db/config');
const { sqlUpdateUserNickName,sqlUpdateUserSignature ,sqlUpdateUserGender,sqlUpdateUserImg} = require('../db/userInfoSql');

/* 修改用户昵称 */
module.exports.UpdateUserNickNameHandler = function (req, res) {
    const nickName = req.body.nickName,
        id = Number(req.body.id);
    
    db.query(sqlUpdateUserNickName, [nickName, id], (error, result) => {
        if (result) {         
            res.send({
                msg: '修改昵称成功'
            });            
        } else {
            res.send({
                msg: '修改昵称失败'
            })
        }
    });
}

/* 修改用户个性签名 */
module.exports.UpdateUserSignatureHandler = function (req, res) {
    const signature = req.body.signature,
        id = Number(req.body.id);
    
    db.query(sqlUpdateUserSignature, [signature, id], (error, result) => {
        if (result) {         
            res.send({
                msg: '修改个性签名成功'
            });            
        } else {
            res.send({
                msg: '修改个性签名失败'
            })
        }
    });
}

/* 修改用户性别 */
module.exports.UpdateUserGenderHandler = function (req, res) {
    const gender = req.body.gender,
        id = Number(req.body.id);
    
    db.query(sqlUpdateUserGender, [gender, id], (error, result) => {
        if (result) {         
            res.send({
                msg: '修改性别成功'
            });            
        } else {
            res.send({
                msg: '修改性别失败'
            })
        }
    });
}


/* 修改用户头像 */
module.exports.UpdateUserImgHandler = function (req, res) {
    const imgUrl = req.body.imgUrl,
        id = Number(req.body.id);
    
    console.log(imgUrl,id)
    
    db.query(sqlUpdateUserImg, [imgUrl, id], (error, result) => {
        if (result) {         
            res.send({
                msg: '修改头像成功'
            });            
        } else {
            res.send({
                msg: '修改头像失败'
            })
        }
    });
}


